package fh.hof.lucene.view;

import javax.swing.*;

//import fh.hof.lucene.controller.FileChooserDemo;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

public class AddDialog extends JDialog {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	JPanel contentPane;
	JFileChooser jfc;
	
	JPanel panName = new JPanel();
	JPanel panAutor = new JPanel();
	JPanel panCategory = new JPanel();
	JPanel panDate = new JPanel();
	JPanel panButtons = new JPanel();
	JPanel panDocPath = new JPanel();
	
	JTextField tfName = new JTextField(30);
	JTextField tfAutor = new JTextField(20);
	JTextField tfCategory = new JTextField(20);;
	JTextField tfDate = new JTextField(20);
	JTextField tfDocPath = new JTextField(50);
	
	JLabel lbName = new JLabel("Name");
	JLabel lbAutor = new JLabel("Autor");
	JLabel lbCategory = new JLabel("Category");;
	JLabel lbDate = new JLabel("Date");
	JLabel lbDocPath = new JLabel("Path");
	
	
	JButton buttDocPath = new JButton("../");
	JButton addButton = new JButton("ADD");
	JButton cancelButton = new JButton("Cancel");
	
	public AddDialog(){
		
		contentPane = (JPanel) getContentPane();
		
		
		panDocPath.setLayout(new BoxLayout (panDocPath, BoxLayout.X_AXIS));
		panDocPath.add(Box.createRigidArea(new Dimension(5,0)));
		panDocPath.add(lbDocPath);
		panDocPath.add(Box.createHorizontalGlue());
		panDocPath.add(tfDocPath);
		panDocPath.add(buttDocPath);
		tfDocPath.setMaximumSize(new Dimension (200,15));
		
		
		panName.setLayout(new BoxLayout (panName, BoxLayout.X_AXIS));
		panName.add(Box.createRigidArea(new Dimension(5,0)));
		panName.add(lbName);
		panName.add(Box.createHorizontalGlue());
		panName.add(tfName);
		tfName.setMaximumSize(new Dimension (200,15));
		
		panAutor.setLayout(new BoxLayout (panAutor, BoxLayout.X_AXIS));
		panAutor.add(Box.createRigidArea(new Dimension(5,0)));
		panAutor.add(lbAutor);
		panAutor.add(Box.createHorizontalGlue());
		panAutor.add(tfAutor);
		tfAutor.setMaximumSize(new Dimension (200,15));
		
		panCategory.setLayout(new BoxLayout (panCategory, BoxLayout.X_AXIS));
		panCategory.add(Box.createRigidArea(new Dimension(5,0)));
		panCategory.add(lbCategory);
		panCategory.add(Box.createHorizontalGlue());
		panCategory.add(tfCategory);
		tfCategory.setMaximumSize(new Dimension (200,15));
		
		panDate.setLayout(new BoxLayout (panDate, BoxLayout.X_AXIS));
		panDate.add(Box.createRigidArea(new Dimension(5,0)));
		panDate.add(lbDate);
		panDate.add(Box.createHorizontalGlue());
		panDate.add(tfDate);
		tfDate.setMaximumSize(new Dimension (200,15));
		
		panButtons.setLayout(new BoxLayout (panButtons, BoxLayout.X_AXIS));
		panButtons.add(Box.createRigidArea(new Dimension(5,0)));
		panButtons.add(addButton);
		panButtons.add(cancelButton);
		
		contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
		contentPane.add(panDocPath);
		contentPane.add(panName);
		contentPane.add(panAutor);
		contentPane.add(panCategory);
		contentPane.add(panDate);
		contentPane.add(panButtons);
		
		jfc = new JFileChooser();
		ActionListener alPath = new ActionListener (){
			
			public void actionPerformed(ActionEvent e){
				int returnVal = jfc.showOpenDialog(AddDialog.this);

	            if (returnVal == JFileChooser.APPROVE_OPTION) {
	                File file = jfc.getSelectedFile();
	                tfDocPath.setText(file.getPath());
				}
			}
		};
		
		buttDocPath.addActionListener(alPath);
	
	}
	
	public static void main (String [] args){
		
		JDialog add = new JDialog();
		add.setVisible(true);
		
	}
}
